package lianxi;

public class Person {
    private String name;
    private int age;
    public Person(){

    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    /*public void keepPet(Dog dog,String something){
        System.out.println(getAge()+"岁的"+getName()+"养了一条"+ dog.getColor()+"颜色的"+dog.getAge()+"岁的狗");
        dog.eat(something);
    }
    public void keepPet(Cat cat,String something){
        System.out.println(getAge()+"岁的"+getName()+"养了一条"+ cat.getColor()+"颜色的"+cat.getAge()+"岁的猫");
        cat.eat(something);
    }*/
    public void keepPet(Animals a,String something){
        if(a instanceof Dog d){
            System.out.println(getAge()+"岁的"+getName()+"养了一条"+ a.getColor()+"颜色的"+a.getAge()+"岁的狗");
            a.eat(something);
        }else if (a instanceof Cat c){
            System.out.println(getAge()+"岁的"+getName()+"养了一条"+ a.getColor()+"颜色的"+a.getAge()+"岁的猫");
            a.eat(something);
        }
    }
}
